﻿using nanhua.BookStore.IApplicationServices;
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
using Volo.Abp.Json.SystemTextJson;

namespace nanhua.BookStore.HttpApi.Client.ConsoleTestApp
{
    public class ClientDemoService : ITransientDependency
    {
        private readonly IProfileAppService _profileAppService;
        private readonly IOrderAppService _orderService;
        protected AbpSystemTextJsonSerializerProvider JsonSerializer1;
        public ClientDemoService(IProfileAppService profileAppService, IOrderAppService orderService,
            AbpSystemTextJsonSerializerProvider JsonSerializer)
        {
            _profileAppService = profileAppService;
            this._orderService = orderService;
            this.JsonSerializer1 = JsonSerializer;
        }

        public async Task RunAsync()
        {
            var output = await _orderService.GetListAsync(new Orders.GetOrderListDto() { SkipCount=0,MaxResultCount =20});
            Console.WriteLine($"目前订单数据已有{output.TotalCount}");

            Console.WriteLine($"新订单创建");

            var requestParam = new Dto.CreateOrderDto()
            {
                OrderDetails = new System.Collections.Generic.List<Dto.CreateOrderDetailDto>()
                {
                    new Dto.CreateOrderDetailDto(){ProductCode ="P_A001",Price =40 },
                    new Dto.CreateOrderDetailDto(){ProductCode ="P_A002",Price =34 }
                }
            };
            var json = this.JsonSerializer1.Serialize(requestParam);
            var ss = JsonSerializer.Serialize(requestParam);
            Console.WriteLine(json);
            var createResult = await _orderService.CreateOrderAsync(requestParam);

            Console.WriteLine($"新订单已创建成果");


            /*Console.WriteLine($"UserName : {output.UserName}");
            Console.WriteLine($"Email    : {output.Email}");
            Console.WriteLine($"Name     : {output.Name}");
            Console.WriteLine($"Surname  : {output.Surname}");*/
        }
    }
}